package store.lunangangster.engine.bpmn.parser.handler;

import store.lunangangster.bpmn.model.BaseElement;
import store.lunangangster.bpmn.model.FlowElementsContainer;
import store.lunangangster.bpmn.model.FlowNode;
import store.lunangangster.bpmn.model.SequenceFlow;
import store.lunangangster.engine.bpmn.parser.BpmnParser;

/**
 * SequenceFlowParseHandler用于解析SequenceFlow，并将相关的source和target对应的FlowNode设置
 * incoming和outgoing属性
 *
 * @author cwk
 * @version 1.0
 */
public class SequenceFlowParseHandler extends AbstractBpmnParseHandler<SequenceFlow> {

  @Override
  public void handle0(BpmnParser bpmnParser, SequenceFlow sequenceFlow) {
    String sourceRef = sequenceFlow.getSourceRef();
    String targetRef = sequenceFlow.getTargetRef();
    FlowElementsContainer parentContainer = sequenceFlow.getParentContainer();
    sequenceFlow.setSource((FlowNode) parentContainer.getFlowElements().get(sourceRef));
    sequenceFlow.setTarget((FlowNode) parentContainer.getFlowElements().get(targetRef));
  }

  @Override
  public Class<? extends BaseElement> getType() {
    return SequenceFlow.class;
  }
}
